<template>
  <div class="root">
    <p>该方法主要利用iframe来满足一些特殊的需求，给iframe添加id也是为了方便使用完针对该id进行删除操作</p>
    <pre>
      <code>
        export function createIframe (dom, src, onload) {
          
          //在document中创建iframe
          var iframe = document.createElement("iframe");
          
          //添加id
          iframe.setAttribute('id','iframe')
          
          //设置iframe的样式
          iframe.style.width = "100%";
          iframe.style.height = "100%";
          iframe.style.margin = "0";
          iframe.style.padding = "0";
          iframe.style.overflow = "hidden";
          iframe.style.border = "none";
          iframe.style.position = "absolute";
          iframe.style.top = "0";
          iframe.style.left = "0";
          iframe.style.zIndex = "100";

          //绑定iframe的onload事件,处理事件的兼容问题
          if (onload && Object.prototype.toString.call(onload) === "[object Function]") {
            if (iframe.attachEvent) {
              iframe.attachEvent("onload", onload);
            } else if (iframe.addEventListener) {
              iframe.addEventListener("load", onload);
            } else {
              iframe.onload = onload;
            }
          }
        
          iframe.src = src;
          //把iframe载入到dom以下
          dom.appendChild(iframe);
          return iframe;
        }
      </code>
    </pre>
  </div>
</template>

<script>
export default {
  components: {},

  data() {
    return {
    };
  },

  created() {},

  mounted() {},

  methods: {
  }
};
</script>

<style lang="less" scoped>
  
</style>
